<?php
class Ticket_model extends Model {
	/**
	 * 添加票
	 * @param unknown_type $cols
	 */
	public function add($cols) {
		$dTicket = new Ticket_data();
		
		return $dTicket->add($cols);
	}
	/**
	 * 获取票信息
	 * @param unknown_type $params
	 */
	public function info($params) {
		$dTicket = new Ticket_data();
		
		$return = $dTicket->info($params);
		if($return) {
			$return['start_time'] = $return['start_time']=='0000-00-00 00:00:00'? '':$return['start_time'];
			$return['end_time'] = $return['end_time']=='0000-00-00 00:00:00'? '':$return['end_time'];
		}
		return $return;
	}
	
	/**
	 * 获取票信息
	 * @param unknown_type $params
	 */
	public function ticketInfoByTid($tid) {
		$dTicket = new Ticket_data();
		
		$params = array('tid in' => $tid);
		$result = $dTicket->ticketInfos($params);
		if(!$result) return false;
		$return = array();
		foreach ($result as $key => $value) {
			$result[$key]['start_time'] = $value['start_time']=='0000-00-00 00:00:00'? '':$value['start_time'];
			$result[$key]['end_time'] = $value['end_time']=='0000-00-00 00:00:00'? '':$value['end_time'];
			$return[$value['tid']] = $result[$key];
		}
		return $return;
	}
	
	/**
	 * 编辑门票
	 * @param unknown_type $params
	 * @param unknown_type $cols
	 */
	public function edit($tid, $cols) {
		$dTicket = new Ticket_data();
		
		$params = array('tid' => $tid);
		return $dTicket->edit($params, $cols);
	}
	/**
	 * 删除门票
	 * @param unknown_type $params
	 */
	public function del($params) {
		$dTicket = new Ticket_data();
		
		return $dTicket->del($params);
	}
	/**
	 * 分页获取角色信息
	 * @param unknown_type $page
	 * @param unknown_type $size
	 * @param unknown_type $params
	 * @param unknown_type $orderby
	 */
	public function page($page, $size, $params = array(), $orderby='`tid` DESC') {
		$dTicket = new Ticket_data();
		
		$num = $dTicket->count($params);
		if($num === false) return false;
		if($num === 0) return array('num' => 0, 'data' => array(), 'page' => $page, 'size' => $size);
		
		$result = $dTicket->page($page, $size, $params, $orderby);
		if(!$result) return false;
		foreach ($result as $key => $value) {
			$result[$key]['start_time'] = $value['start_time']=='0000-00-00 00:00:00'? '':$value['start_time'];
			$result[$key]['end_time'] = $value['end_time']=='0000-00-00 00:00:00'? '':$value['end_time'];
		}
		return array('num' => $num, 'data' => $result, 'page' => $page, 'size' => $size);
	}
}